#include <iostream>

const int N = 2e5 + 5;
typedef long long LL;
char s[N];
struct xq {
    int l, r, sum, flag;
} tr[N << 2];
void BuildTree(int i, int l, int r) {
    tr[i].l = l, tr[i].r = r;
    if (l == r) {
        tr[i].sum = s[l] & 1;
        return ;
    }
    int mid = l + r >> 1;
    BuildTree(i << 1, l, mid);
    BuildTree(i << 1 | 1, mid + 1, r);
    tr[i].sum = tr[i << 1].sum + tr[i << 1 | 1].sum;
}
void DeclineTag(int i) {
    if (tr[i].flag) {
        for (int mid = i << 1; mid <= (i << 1 | 1); ++ mid) {
            tr[mid].sum = tr[mid].r - tr[mid].l + 1 - tr[mid].sum;
            tr[mid].flag ^= 1;
        }
    }
    tr[i].flag = 0;
}
void ModT(int i, int l, int r) {
    if (l <= tr[i].l && r >= tr[i].r) {
        tr[i].sum = tr[i].r - tr[i].l + 1 - tr[i].sum;
        tr[i].flag ^= 1;
        return ;
    }
    DeclineTag(i);
    if (tr[i << 1].r >= l) ModT(i << 1, l, r);
    if (tr[i << 1 | 1].l <= r) ModT(i << 1 | 1, l , r);
    tr[i].sum = tr[i << 1].sum + tr[i << 1 | 1].sum;
}
int check(int i, int l, int r) {
    if (l <= tr[i].l && r >= tr[i].r) 
        return tr[i].sum;
    DeclineTag(i);
    int all = 0;
    if (tr[i << 1].r >= l) all = check(i << 1, l, r);
    if (tr[i << 1 | 1].l <= r) all += check(i << 1 | 1, l, r);
    return all;
}
signed main() {
    int n, m;
    scanf("%d %d", &n, &m);
    scanf(" %s", s + 1);
    BuildTree(1, 1, n);
    for (int i = 1; i <= m; ++ i) {
        int op, l, r;
        scanf("%d %d %d", &op, &l, &r);
        if (op & 1) {
            printf("%d\n", check(1, l, r));
        } else {
            ModT(1, l, r);
        }
    }

    return 0;
}